package com.abe.bathsystem.widget.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.abe.bathsystem.entity.http.HttpVersionEntity;
import com.abe.bathsystem.utils.ConstantBath;
import com.abe.libcore.utils.normal.ToastUtils;

import net.yet.campusdev.R;

public class VersionDialog extends BaseDialog {
    private HttpVersionEntity versionEntity;

    private DialogContract.OnUpdateListener listener;

    public VersionDialog(@NonNull Context context, HttpVersionEntity versionEntity) {
        super(context);
        this.versionEntity = versionEntity;
    }

    public void setListener(DialogContract.OnUpdateListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.item_view_v3_version_check);
        ((TextView) findViewById(R.id.item_version_msg)).setText(versionEntity.getMsg());
        findViewById(R.id.item_btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onUpdate(false, null);
                } else {
                    ToastUtils.show("请绑定回调监听");
                }
                dismiss();
            }
        });
        findViewById(R.id.item_btn_confrim).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onUpdate(true, ConstantBath.AppDownUrl + versionEntity.getResId());
                } else {
                    ToastUtils.show("请绑定回调监听");
                }
                dismiss();
            }
        });
    }
}
